package com.itheima.health.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.CheckGroupDao;
import com.itheima.health.dao.CheckItemDao;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.exception.BusinessRuntimeException;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 * @author sot
 * @description 检查组service实现类
 **/
@Slf4j
@Service
public class CheckGroupServiceImpl implements CheckGroupService {
    @Autowired
    private CheckGroupDao checkGroupDao;

    @Override
    public void add(CheckGroup checkGroup) {
        log.info("需要添加的检查组基本信息");
        checkGroupDao.add(checkGroup);
    }

    @Override
    public void addCheckitemAndCheckgroupWithId(Integer checkGroupId, Integer checkitemId) {
        checkGroupDao.addCheckitemAndCheckgroupWithId(checkGroupId,checkitemId);
    }

    @Override
    public PageResult queryPage(QueryPageBean queryPageBean) {
        //分页查询插件 需要传入 查询页码 与 每页多少条 即可自动在sql语句后加上limit n , m
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        //分页查询数据库 参数为模糊查询条件 有模糊查询传入 没有不传
        Page<CheckGroup> page = checkGroupDao.selectByQuery(queryPageBean.getQueryString());
        //封装分页查询得到的数据
        return new PageResult(page.getTotal(),page.getResult());
    }



    @Override
    public CheckGroup findByid(Integer id) {
        return checkGroupDao.findByid(id);
    }

    @Override
    public List<Integer> findCheckItemIdsByCheckGroupId(Integer id) {
        return checkGroupDao.findCheckItemIdsByCheckGroupId(id);
    }

    @Override
    public void updateEdit(CheckGroup checkGroup) {
        checkGroupDao.updateEdit(checkGroup);
    }

    @Override
    public void deleteById(Integer checkGroupId) {
        checkGroupDao.deleteById(checkGroupId);
    }

    @Override
    public void deleteCheckGroupitemById(Integer id) {
        checkGroupDao.deleteCheckGroupitemById(id);
    }

    @Override
    public List<CheckGroup> findAll() {
        return checkGroupDao.findAll();
    }


}
